package com.tudouji.project.harvest.service.impl;

import com.flow.service.process.service.IBaseServiceFactory;
import com.flow.service.process.service.IFlowBaseService;
import com.flow.service.utils.SpringContextUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
@Service
@Slf4j
public class BaseServiceFactory implements IBaseServiceFactory {
    private static final Map<Long,String> serviceMap=new HashMap<Long,String>();

    static {
        serviceMap.put(Long.valueOf(26),"purchasebillServiceImpl");
        serviceMap.put(Long.valueOf(27),"transferapplyServiceImpl");
        serviceMap.put(Long.valueOf(28),"transferapplyServiceImpl");
        serviceMap.put(Long.valueOf(29),"customerServiceImpl");
        serviceMap.put(Long.valueOf(30),"pickinglistServiceImpl");
        serviceMap.put(Long.valueOf(31),"materialretapplyServiceImpl");
        serviceMap.put(Long.valueOf(33),"whinapplyServiceImpl");
        //20231025 旧销售订单加入进来，以便查询审批记录
        serviceMap.put(Long.valueOf(2),"sellformServiceImpl");
        serviceMap.put(Long.valueOf(34),"sellformServiceImpl");
        serviceMap.put(Long.valueOf(35),"sellformServiceImpl");
        serviceMap.put(Long.valueOf(36),"sellformServiceImpl");
        serviceMap.put(Long.valueOf(37),"rechargeServiceImpl");
        serviceMap.put(Long.valueOf(38),"farepayApplyServiceImpl");
        //采收合同
        serviceMap.put(Long.valueOf(39),"procurementcontractServiceImpl");
        //采收货运单
        serviceMap.put(Long.valueOf(40),"freightorderServiceImpl");
        //付款申请单
        serviceMap.put(Long.valueOf(41),"payinfoServiceImpl");
        //付款申请单
        serviceMap.put(Long.valueOf(42),"payinfoServiceImpl");
        //添加新的...
    }
    public static IFlowBaseService getFlowBaseServiceById(Long id){
        String beanName = serviceMap.get(id);
        if (beanName == null){
            return null;
        }
        try{
            return SpringContextUtils.getBean(beanName,IFlowBaseService.class);
        }catch(Exception e){
            e.printStackTrace();
            return null;
        }

    }
    public static void test(){
        try {
            Map<String, IFlowBaseService> beans = SpringContextUtils.getBeans(IFlowBaseService.class);

            for(String s:serviceMap.values()){
                System.out.println("=====:" + SpringContextUtils.getBean(s,IFlowBaseService.class));
            }
            for (IFlowBaseService ifs : beans.values()) {
                System.out.println("=====:" + ifs);
            }
        }catch (Exception e){
            System.out.println("exception:" + e.getMessage());
        }
    }

    @Override
    public IFlowBaseService getFlowBaseServiceByIdImpl(Long id) {
        return getFlowBaseServiceById(id);
    }
}
